import { numToHex, strToHex } from "src/util"

export default function msgResponse(deviceId:string, packDir:'00'|'01', type:string, str:string) {
    let msg = '2878' + packDir + type
    let d = new Date()
    let time = d.getTime()
    msg += numToHex(Math.floor(time / 1000), 8)
    msg += numToHex(time % 1000, 4)

    let followData = '00' + '0000000000000000' + deviceId + strToHex(str, 0) + '0000' + '1555'
    let length = numToHex(followData.length, 4)

    return JSON.stringify({deviceId : deviceId, body : msg + length + followData})
}